import {
  receiptMoneyTable,
  downloadReceipt
} from '../../../network/finance'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    receiptMoneyInfo: [],
    receiptDown:""
  },
  toDetails: function () {
    wx.switchTab({
      url: '/pages/finance/finance/finance',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this._getReceiptMoneyTable()
  },
  // 下载数据请求
  async _getDownloadReceipt(e) {
    console.log("e", e);
    let data = {
      id: e.currentTarget.dataset.id
    }
    const res = await downloadReceipt(data)
    console.log("下载数据", res);
    if(res.code){
      this.setData({
        receiptDown:res.data
      })
    }

    wx.downloadFile({
      url: `http://master.gddzxcx.com/${this.data.receiptDown}`,
      success: function (res) {
        var filePath = res.tempFilePath;
        wx.openDocument({
          filePath: filePath,
          success: function (res) {
            console.log('打开文档成功')
          }
        })
      }
    })
  },

  // 网络请求 //
  async _getReceiptMoneyTable() {

    const res = await receiptMoneyTable()
    console.log("收款表列表", res.data.data);
    if (res.code === 200) {
      this.setData({
        receiptMoneyInfo: res.data.data
      })
    }

  }

})